<?php
/********************************************************
 *
 * 此文件的作用:
 *		家教部后台控制器
 *
 * @copyright Copyright (c) 2008-2009
 * @author 刘昌功 lcg635@126.com
 *
 ********************************************************/
defined('APP_DIR') or die('404 Not Found');

FLEA::loadClass('Common_AdminAction');

class Controller_AdminWork extends Common_AdminAction {
	function __construct($ctlName)   {
		parent::__construct($ctlName);
		$this->tplDir = TPL_A;
	}
	
	
	/*****************员工操作***********************************/
	
	function index(){
		echo 'index';
	}
	
	function workerConnect(){//生成通讯录
	    $viewData = unserialize($_SESSION['workerConnect']);
		$this->_out('manpower/workerConnect',$viewData);
	}
	
	function listWorkers(){//查看所有员工
		$_modWorker = FLEA::getSingleton('Model_Worker');
		$_modUser = FLEA::getSingleton('Model_User');
		$ui = FLEA::initWebControls();
		$page = $this->saveGet('page');
		$viewData = $_modWorker->getAllWorkers($page);
		$workerConnect= serialize($viewData);
		$_SESSION['workerConnect'] =$workerConnect;
		$viewData['form']['worker'] = $_modWorker->searchForm();
		$viewData['form']['connect'] = $_modWorker->connectForm($viewData);
		$viewData['pagerData1'] = $ui->control('pagernav', 'pagenav',//为什么pageData后要有1？？？？？？？
			array('pager'=>$viewData['pagerData'],'controller'=>'AdminWork', 'action'=>'listWorkers' ),
			true
		);

		$this->_out('manpower/listWorkers',$viewData);
		
	}
	
	function viewWorker(){//查看特定员工
		$_modWorker = FLEA::getSingleton('Model_Worker');
		$_modUser = FLEA::getSingleton('Model_User');
		$_modProcess = FLEA::getSingleton('Model_Process');
		$viewData = array(
			'user' => $_modUser->getUserInfo($this->saveGet('user_id'), 'work'), 
			'process' => $_modProcess->getList($this->saveGet('user_id')), 
			'processForm' => $_modProcess->getForm($this->saveGet('user_id')) 
			);
		//dump($viewData);
		$this->_out('manpower/viewWorker', $viewData);
	}
	
	function searchWorkers(){  //员工搜索
		$_modworker = FLEA::getSingleton('Model_Worker');
		$_modUser = FLEA::getSingleton('Model_User');
		$ui = FLEA::initWebControls();
		$viewData = $_modworker->search($_POST, $this->saveGet('page'));
		$workerConnect= serialize($viewData);
		$_SESSION['workerConnect'] =$workerConnect;
		$viewData['form']['worker'] = $_modworker->searchForm();
		//$viewData['form']['connect'] = $_modWorker->connectForm($viewData);
		//$viewData['act'] = 'SearchTeacher';
		$viewData['pagerData1'] = $ui->control('pagernav', 'pagenav',
			array('pager'=>$viewData['pagerData'],'controller'=>'AdminWork', 'action'=>'searchworkers' ),
			true
		);
		//dump($viewData);
		$this->_out('manpower/listWorkers',$viewData);
	}
	
	function delProcess(){
		$_modProcess = FLEA::getSingleton('Model_Process');
		$_modProcess->delProcess($this->saveGet('process_id'));
		redirect($_SERVER['HTTP_REFERER']);
	}
	
	function addProcess(){
		$data = $_POST;
		if($data['number'] || $data['comment'] || $data['result'] || $data['group'] || $data['processer']){
			$_modProcess = FLEA::getSingleton('Model_Process');
			$_modWorker = FLEA::getSingleton('Model_Worker');
			$_modUser = FLEA::getSingleton('Model_User');
			$_modProcess->addProcess($data);
			
			if ($data['result'] || $data['group']){
				$userData = $_modUser->getInfo($data['user_id']);
				//dump($userData);
				$_modWorker->addWorkNum($userData['work'],$data['group'],$data['result']);
			}
			if($data['number']){
				$userData = $_modUser->getInfo($data['user_id']);
				//dump($userData);
				$_modWorker->updateWorkNum($userData['work'],$data['number']);
			}

			redirect($_SERVER['HTTP_REFERER']);
		}else {
			js_alert('审核内容为空',null,$_SERVER['HTTP_REFERER']);	
		}

	}
	
	function prints() {//打印员工表，未可用
		if ( $this->user['userid'] == null ) {
			js_alert('您还没有登录，请先登录系统', null, url());
		}

		$_modUser = FLEA::getSingleton('Model_User');
		$viewData = array('user' => $_modUser->getUserInfo($this->user['userid'], 'work') );
		//dump($viewData);
		$this->_out('manpower/print', $viewData);
	}
	
	function realWorkers($type = '正式员工',$type2='realWorkers'){
		$_modworker = FLEA::getSingleton('Model_Worker');
		$_modUser = FLEA::getSingleton('Model_User');
		$ui = FLEA::initWebControls();
		$viewData = $_modworker->searchRealWorkers($_POST, $this->saveGet('page'),10,$type);
		$workerConnect= serialize($viewData);
		$_SESSION['workerConnect'] =$workerConnect;
		$viewData['form']['worker'] = $_modworker->searchForm();
		//$viewData['form']['connect'] = $_modWorker->connectForm($viewData);
		//$viewData['act'] = 'SearchTeacher';
		$viewData['pagerData1'] = $ui->control('pagernav', 'pagenav',
			array('pager'=>$viewData['pagerData'],'controller'=>'AdminWork', 'action'=>$type2 ),
			true
		);
		//dump($viewData);
		$this->_out('listWorkers',$viewData);		
	}
	
	function unrealWorkers(){
		$this->realWorkers('待审核','unrealWorkers');
	}
	function testWorkers(){
		$this->realWorkers('进入试用','testWorkers');
	}
	function notWorkers(){
		$this->realWorkers('已辞职','notWorkers');
	}
		function failWorkers(){
		$this->realWorkers('审核失败','failWorkers');
	}
	function blackWorkers(){
		$this->realWorkers('黑名单','blackWorkers');
	}
	


/*****************员工操作结束***********************************/


}
